#ifndef ARROW_H
#define ARROW_H

#include <QGraphicsPathItem>
#include "gactiveelement.h"
#include "gpool.h"
class QGraphicsSvgItem;
class QDomElement;


class Link : public QGraphicsPathItem
{
public:
	//The first two parameters are linked items,
	//the third provides start point,
	//the second also specify the end point.
	Link(GActiveElement *startItem, GPool *endItem, const QString & portName, QGraphicsItem *parent = 0);
	~Link();

	// Enable the use of qgraphicsitem_cast with this item.
	enum { Type = UserType + 4 };
	int type() const { return Type; }

	//serve for XML serialization.
	QString startObject() const { return mStartItem->elementName(); }
	QString startPort() const { return mStartItem->portName(mStart); }
	QString endObject() const { return mEndItem->elementName(); }

	static QPainterPath calPath(const QPointF p1, const QPointF p2, const QString direction);

	void updatePosition();

protected:
	void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);

private:
	GActiveElement *mStartItem;
	GPool *mEndItem;
	QGraphicsSvgItem* mStart;
	QString mDirection; //serve for calPath
};

#endif // ARROW_H
